﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StockSBIE
{
    public class DateUtils
    {

        public static String getYYYYMMDDHHSS(DateTime d)
        {
            if(d!=null)
                return String.Format("{0}/{1:00}/{2:00} {3:00}:{4:00}", d.Year, d.Month, d.Day,d.Hour,d.Minute );
            return "";
        }
        public static DateTime getValidTradeDate(DateTime d)
        {
            if (d.DayOfWeek.Equals(DayOfWeek.Saturday))
            {
                return d.AddDays(-1);
            }
            if (d.DayOfWeek.Equals(DayOfWeek.Sunday))
            {
                return d.AddDays(-2);
            }
            if (d.Hour < 14)
            {
                d = d.AddHours(15 - d.Hour);
                return getValidTradeDate(d.AddDays(-1));
            }
            return d;
        }

        public static String getSlashYYYYMMDD(DateTime d)
        {
               return String.Format("{0}/{1:00}/{2:00}", d.Year, d.Month, d.Day);
        }

        public static String getYYYYMMPlanString(DateTime d)
        {
            return String.Format("{0}{1:00}", d.Year, d.Month);
        }

        public static String getPlanString(DateTime d)
        {
            return String.Format("{0}{1:00}{2:00}", d.Year, d.Month, d.Day);
        }
        public static String getROCString(DateTime d)
        {
            return String.Format("{0}/{1:00}/{2:00}", d.Year - 1911, d.Month, d.Day);
        }
    }
}
